package com.sbhotel.chotellauncher.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.sbhotel.chotellauncher.R;
import com.sbhotel.chotellauncher.adapter.SleepTurnOffAdapter;
import com.sbhotel.chotellauncher.constant.Constants;
import com.sbhotel.chotellauncher.util.SPUtil;
import com.sbhotel.chotellauncher.util.Utils;

import java.util.List;

public class SleepTurnOffActivity extends BaseActivity implements View.OnClickListener {

    ListView lv;
    SleepTurnOffAdapter adapter;
    List<String> listData;
    TextView tvClose, tvValue30, tvValue60, tvValue90;

    @Override
    public void initView() {
        /*lv = findViewById(R.id.lv_sleep_turn_off);
        listData = Constants.initSleepTurnOffData();
        adapter = new SleepTurnOffAdapter(this, listData);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(SleepTurnOffActivity.this, listData.get(i), Toast.LENGTH_SHORT).show();
            }
        });*/
        tvClose = findViewById(R.id.tv_sleep_colose);
        tvValue30 = findViewById(R.id.tv_sleep_value_30);
        tvValue60 = findViewById(R.id.tv_sleep_value_60);
        tvValue90 = findViewById(R.id.tv_sleep_value_90);
        tvClose.setOnClickListener(this);
        tvValue30.setOnClickListener(this);
        tvValue60.setOnClickListener(this);
        tvValue90.setOnClickListener(this);
    }

    @Override
    public void initData() {
        initTitleBar("睡眠关机", "");
    }

    @Override
    public int initLayout() {
        return R.layout.activity_sleep_turn_off;
    }

    @Override
    public void onClick(View view) {
        String result;
        Intent intent = new Intent();
        switch (view.getId()) {
            case R.id.tv_sleep_colose:
                result = tvClose.getText().toString();
                break;
            case R.id.tv_sleep_value_30:
                result = tvValue30.getText().toString();
                Utils.startAlarm(this, 30);
                break;
            case R.id.tv_sleep_value_60:
                result = tvValue60.getText().toString();
                Utils.startAlarm(this, 60);
                break;
            case R.id.tv_sleep_value_90:
                result = tvValue90.getText().toString();
                Utils.startAlarm(this, 90);
                break;
            default:
                result = tvClose.getText().toString();
                break;
        }
        if (!TextUtils.isEmpty(result)) {
            intent.putExtra("result", result);
            SPUtil.put(SleepTurnOffActivity.this, Constants.SP_KEY_SLEEP_VALUE, result);
            setResult(1, intent);
            finish();
        }
    }

    @Override
    public void onBackPressed() {
        Intent intent = new Intent();
        intent.putExtra("result", "");
        //SPUtil.put(SleepTurnOffActivity.this, "sleep_value", result);
        setResult(1, intent);
        finish();
    }
}
